<template>
  <div class="header">
    <el-card style="height: 60px" :body-style="{ padding: '0px' }">
      <div class="content">
        <div class="left">
          <el-icon
            size="30"
            v-if="isCollapse == false"
            style="margin-left: 10px; cursor: pointer"
            @click="foldChange"
            ><Fold
          /></el-icon>
          <el-icon
            size="30"
            v-if="isCollapse == true"
            style="margin-left: 10px; cursor: pointer"
            @click="foldChange"
            ><Expand
          /></el-icon>
          <el-breadcrumb separator="/" style="margin-left: 20px">
            <!-- <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/' }">课程管理</el-breadcrumb-item> -->
            <el-breadcrumb-item :to="{ path: '/home' }"
              >主页</el-breadcrumb-item
            >
            <el-breadcrumb-item :to="{ path: Route.path }">{{
              Route.meta.title
            }}</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <div class="right">
          <!-- <i class="el-icon-quanping" style="font-size: 26px" @click="handleFull"></i> -->
          <el-icon
            style="font-size: 32px; cursor: pointer; margin-right: 10px"
            color="rgb(121.3, 187.1, 255)"
            @click="handleFull"
            ><FullScreen
          /></el-icon>
          <img
            :src="
              imgUrl ||
              'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'
            "
            alt=""
            style="width: 40px; height: 40px; border-radius: 50%; margin: 0 5px"
          />

          <el-dropdown placement="bottom">
            <span
              style="
                margin-right: 15px;
                color: black;
                font-size: 28px;
                cursor: pointer;
              "
              >{{ user.username }}</span
            >
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click.native="$router.push('/person')"
                  >个人信息</el-dropdown-item
                >
                <el-dropdown-item @click.native="$router.push('/change')"
                  >修改密码</el-dropdown-item
                >
                <el-dropdown-item @click.native="logout"
                  >退出登录</el-dropdown-item
                >
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </div>
    </el-card>
    <!-- <Aside /> -->
  </div>
</template>

<script setup>
import { getAvatar } from "@/api/header";
import { ElMessage } from "element-plus";
import { ref } from "vue";
import { useRoute, useRouter } from "vue-router";
// import { useRoute, useRouter } from 'vue-router';
const imgUrl = ref(
  "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"
);
const router = useRouter();
// import Aside from '@/components/aside/Aside.vue'
const isCollapse = ref(false);
const Route = useRoute();

const emits = defineEmits(["fromBrother"]);
const foldChange = () => {
  isCollapse.value = !isCollapse.value;
  console.log(isCollapse.value);
  emits("fromBrother", isCollapse.value);
};
// console.log(isCollapse.value)
const user = JSON.parse(localStorage.getItem("user"));
console.log(user);
const logout = () => {
  localStorage.removeItem("user");
  router.push("/");
  ElMessage({
    //   showClose: true,
    message: "登出成功",
    type: "success",
  });
};
const handleFull = () => {
  document.documentElement.requestFullscreen();
};
const getAvatarUrl = async () => {
  const res = await getAvatar(user.id);
  if (res.code == 200) {
    imgUrl.value = res.data.avatar;
    // console.log(res)
  }
  // user.url = res.data.url
};
getAvatarUrl();
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  outline: none !important;
  -webkit-tap-highlight-color: transparent;
  /* -webkit-appearance: none; */
}
.header {
  width: 100%;
  height: 60px;
  /* background-color: darkcyan; */
}
.content {
  display: flex;
  /* justify-content: center; */
  align-items: center;
  line-height: 60px;
}
.left {
  /* width: 200px; */
  height: 60px;
  flex: 1;
  display: flex;
  align-items: center;
  /* justify-content: center; */
  /* background-color: yellow; */
}
.right {
  /* width: 200px; */
  height: 60px;
  display: flex;
  flex: 1;
  /* justify-content: flex-end; */
  /* background-color: green; */
  align-items: center;
  justify-content: flex-end;
  /* line-height: 60px; */
  /* style="flex: 1; width: 0; display: flex; align-items: center; justify-content: flex-end" */
}
.el-dropdown {
  outline: none !important; /* 使用 !important 强制覆盖 */
}
.el-dropdown-menu,
.el-dropdown-menu:focus,
.el-dropdown-menu:hover,
.el-dropdown-menu:active {
  outline: none; /* 去掉聚焦和悬停时的轮廓 */
}
</style>